// 读取Blog

function responseJSON(json) {
	if (json) {
		response.write(JSON.stringify(json));
	}
	end();
}

on('start', function () {
	var blog = require('./#BlogLogic.js');

	if (typeof blog == 'string') {
		responseJSON({error: blog});
		return;
	}
	
	blog.connect(function (err) {
		if (err) {
			responseJSON({error: err});
			return;
		}
		
		// 查询指定ID的文章内容
		var id = request.GET.id;
		if (!id) {
			responseJSON({error: 'Cannot read the article of null.'})
		}
		blog.read(id, function (err, resoult) {
			if (err) {
				responseJSON({error: err});
			}
			else if (resoult.length > 0) {
				responseJSON({resoult: resoult[0]});
			}
			else {
				responseJSON({});
			}
		});
		
	});
	
});
